package com.skyz.wrap.utils;

import android.app.Activity;

import com.framgia.android.emulator.EmulatorDetector;
import com.skyz.base.manager.EnvironmentManager;

public class EmulatorDetectorUtil {
    private EmulatorDetectorUtil(){

    }
    private static EmulatorDetectorUtil instance = new EmulatorDetectorUtil();

    public static EmulatorDetectorUtil getInstance(){
        return  instance;
    }

    public void check(Activity context, CallBack callBack){
        String envName = EnvironmentManager.getInstance().getCheckedEnvironment().getName();
        //测试环境不检测模拟器
        if ("TEST".equals(envName)){
            if (callBack==null){
                return;
            }
            callBack.onCheckResult(false);
            return;
        }
        EmulatorDetector.with(context)
                .setCheckTelephony(false)
                .addPackageName("com.bluestacks")
                .setDebug(true)
                .detect(new EmulatorDetector.OnEmulatorDetectorListener() {
                    @Override
                    public void onResult(boolean isEmulator) {
                        if (callBack==null){
                            return;
                        }
                        context.runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                callBack.onCheckResult(isEmulator);
                            }
                        });
                    }
                });
    }

    public interface CallBack{
        void onCheckResult(boolean check);
    }
}
